/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Test;

import MNetSockets.DataChanel.IUDPDataReader;
import UDPFiles.IUDPFileStateEvent;
import UDPFiles.UDPCmdFinal;
import UDPFiles.UDPFileServer;
import java.io.File;
import java.net.SocketAddress;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wcss
 */
public class UDPFileShareTest extends javax.swing.JFrame implements  IUDPDataReader,IUDPFileStateEvent {

    private UDPFileServer ufsA = null;

    /**
     * Creates new form UDPFileShareTest
     */
    public UDPFileShareTest(int port,File shareFile) {
        initComponents();

        this.lblName.setText(port + "");
        try {
            ufsA = new UDPFileServer(port, "/home/wcss/.UDPTest_A");
        } catch (Exception ex) {
            Logger.getLogger(UDPFileShareTest.class.getName()).log(Level.SEVERE, null, ex);
        }
        ufsA.stateEvent = this;
        ufsA.dataReceiveEvent = this;
        try {
            ufsA.addShare(shareFile);
        } catch (Exception ex) {
            Logger.getLogger(UDPFileShareTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblInfo = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblInfo.setText("jLabel1");

        lblName.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lblInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(225, 225, 225)
                        .addComponent(lblName, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 278, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblName, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(lblInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblInfo;
    private javax.swing.JLabel lblName;
    // End of variables declaration//GEN-END:variables

    @Override
    public void changeState(Object sender, String statecode, String text) {
        if (statecode.equals(UDPCmdFinal.requestState)) {
            this.lblInfo.setText("当前正在上传：" + text + "号数据包");
        }

    }

    @Override
    public void dataRead(Object o, SocketAddress sa, Object o1) 
    {
        
    }
}
